﻿/*
____
 L|ypps Web controls for ASP.NET

Copyright (c) 2009 Alessandro Zifiglio, http://www.Typps.com
EMail: alessandro@Typps.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
namespace Typps
{
    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    internal class StyleUtility
    {
        #region Fields

        static string[] activeButtonStyleValue = { "ActiveButtonStyle", "activebutton" };
        static string[] blockQuoteDesignViewStyleValue = { "BlockQuoteDesignViewStyle", "htmlelementlabels blockquote" };
        static string colorPickerValue = "ColorPicker";
        static string[] designAreaValue = { "DesignArea", "designarea" };
        static string[] divDesignViewStyleValue = { "DivDesignViewStyle", "htmlelementlabels div" };
        static string[] dropDownClassNameListHoverStyleValue = { "DropDownClassNameListHoverStyle", "dropdownclassnamelist-hover" };
        static string[] dropDownClassNameListStyleValue = { "DropDownClassNameListStyle", "dropdownclassnamelist" };
        static string[] dropDownFontnameHoverStyleValue = { "DropDownFontnameHoverStyle", "dropdownfontname-hover" };
        static string[] dropDownFontnameStyleValue = { "DropDownFontnameStyle", "dropdownfontname" };
        static string[] dropDownFontsizeHoverStyleValue = { "DropDownFontsizeHoverStyle", "dropdownfontsize-hover" };
        static string[] dropDownFontsizeStyleValue = { "DropDownFontsizeStyle", "dropdownfontsize" };
        static string[] dropDownFormatblockHoverStyleValue = { "DropDownFormatblockHoverStyle", "dropdownformatblock-hover" };
        static string[] dropDownFormatblockStyleValue = { "DropDownFormatblockStyle", "dropdownformatblock" };
        static string[] dropDownHeaderStyleValue = { "DropDownHeaderStyle", "dropdownheaderstyle" };
        static string[] dropDownSpellCheckerActiveStyleValue = { "DropDownSpellCheckerActiveStyle", "dropdownspellcheckeractive" };
        static string[] dropDownSpellCheckerHoverStyleValue = { "DropDownSpellCheckerHoverStyle", "dropdownspellchecker-hover" };
        static string[] dropDownSpellCheckerStyleValue = { "DropDownSpellCheckerStyle", "dropdownspellchecker" };
        static string[] dropDownSpellSuggestionHoverStyleValue = { "DropDownSpellSuggestionHoverStyle", "dropdownspellsuggestion-hover" };
        static string[] dropDownSpellSuggestionMenuItemHoverStyleValue = { "DropDownSpellSuggestionMenuItemHoverStyle", "dropdownspellsuggestion-menu-hover" };
        static string[] dropDownSpellSuggestionMenuItemStyleValue = { "DropDownSpellSuggestionMenuItemStyle", "dropdownspellsuggestion-menu" };
        static string[] dropDownSpellSuggestionMenuStyleValue = { "DropDownSpellSuggestionMenuStyle", "dropdownspellsuggestion" };
        static string[] dropDownStyleValue = { "DropDownStyle", "dropdownstyle" };
        static string editorValue = "Editor";
        static string f1 = "{0}-{1}";
        static string f2 = "{0} {1}";
        static string[] firstButtonStyleValue = { "FirstButtonStyle", "firstbutton" };
        static string[] floatingToolBarStyleValue = { "FloatingToolBarStyle", "floatingToolBar" };
        static string[] htmlElementHilightStyleValue = { "HtmlElementHilightStyle", "htmlelementhilightstyle" };
        static string[] htmlViewColorHilightStyleValue = { "HtmlViewColorHilightStyle", "htmlviewcolorhilight" };
        static string[] htmlViewStyleValue = { "HtmlViewStyle", "htmlview" };
        static string[] iFrameBodyStyleValue = { "IFrameBodyStyle", "iframebodystyle" };
        static string[] iFrameHtmlStyleValue = { "IFrameHtmlStyle", "iframehtmlstyle" };
        static string imagePickerValue = "ImagePicker";
        static string[] lastButtonStyleValue = { "LastButtonStyle", "lastbutton" };
        static string[] listItemDesignViewStyleValue = { "ListItemDesignViewStyle", "htmlelementlabels li" };
        static string[] mediaFrameBodyStyleValue = { "MediaFrameBodyStyle", "mediaframebody" };
        static string[] mediaFrameCloseButtonStyleValue = { "MediaFrameCloseButtonStyle", "mediaframeclosebutton" };
        static string[] mediaFrameHeaderCaptionStyleValue = { "MediaFrameHeaderCaptionStyle", "mediaframeheadercaption" };
        static string[] mediaFrameHeaderStyleValue = { "MediaFrameHeaderStyle", "mediaframeheader" };
        static string[] mediaFrameStyleValue = { "MediaFrameStyle", "mediaframe" };
        static string mediaFrameValue = "MediaFrame";
        static string[] nextButtonStyleValue = { "NextButtonStyle", "nextbutton" };
        static string[] pagerButtonHoverStyleValue = { "PagerButtonHoverStyle", "pagerbutton:hover" };
        static string[] pagerButtonStyleValue = { "PagerButtonStyle", "pagerbutton" };
        static string[] paragraphDesignViewStyleValue = { "ParagraphDesignViewStyle", "htmlelementlabels p" };
        static string[] pauseButtonStyleValue = { "PauseButtonStyle", "pausebutton" };
        static string[] popupBodyStyleValue = { "PopupBodyStyle", "popupbody" };
        static string[] popupHeaderCaptionStyleValue = { "PopupHeaderCaptionStyle", "popupheadercaption" };
        static string[] popupHeaderStyleValue = { "PopupHeaderStyle", "popupheader" };
        static string[] popupStyleValue = { "PopupStyle", "popup" };
        static string[] previousButtonStyleValue = { "PreviousButtonStyle", "previousbutton" };
        static string[] progressbarMessageStyleValue = { "ProgressbarMessageStyle", "progressbar p" };
        static string[] progressbarStyleValue = { "ProgressbarStyle", "progressbar" };
        static string[] selectedPagerButtonStyleValue = { "SelectedPagerButtonStyle", "selectedpagerbutton" };
        static string[] slideShowButtonStyleValue = { "SlideShowButtonStyle", "slideshowbutton" };
        static string[] spanDesignViewStyleValue = { "SpanDesignViewStyle", "htmlelementlabels span" };
        static string[] tabContainerStyleValue = { "TabContainerStyle", "tabcontainer" };
        static string[] tabItemHoverStyleValue = { "TabItemHoverStyle", "tabhoverbutton" };
        static string tabItemStyleValue = "TabItemStyle";
        static string[] tableCellDesignViewStyleValue = { "TableCellDesignViewStyle", "htmlelementlabels td" };
        static string tabStyleValue = "TabStyle";
        static string[] thumbnailsContainerStyleValue = { "ThumbnailsContainerStyle", "thumbnailscontainer" };
        static string[] thumbnailStyleValue = { "ThumbnailStyle", "thumbnail" };
        static string[] toolBarItemHoverStyleValue = { "ToolBarItemHoverStyle", "toolBarhoverbutton" };
        static string toolBarItemStyleValue = "ToolBarItemStyle";
        static string toolBarStyleValue = "ToolBarStyle";
        static string updatePanelProgressValue = "UpdatePanelProgress";
        static string[] warningsLogStyleValue = { "WarningsLogStyle", "warningslog" };

        string classNameValue;

        #endregion Fields

        #region Constructors

        public StyleUtility(string className)
        {
            classNameValue = className;
        }

        #endregion Constructors

        #region Properties

        public StyleItem ActiveButtonStyle
        {
            get
            {
                return new StyleItem(activeButtonStyleValue[0],
                    string.Format(f1, ClassName, activeButtonStyleValue[1]));
            }
        }

        public StyleItem BlockQuoteDesignViewStyle
        {
            get
            {
                return new StyleItem(blockQuoteDesignViewStyleValue[0],
                string.Format(f1, ClassName, blockQuoteDesignViewStyleValue[1]));
            }
        }

        public StyleItem ColorPicker
        {
            get
            {
                return new StyleItem(colorPickerValue, ClassName);
            }
        }

        public StyleItem DesignArea
        {
            get
            {
                return new StyleItem(designAreaValue[0],
                    string.Format(f1, ClassName, designAreaValue[1]));
            }
        }

        public StyleItem DivDesignViewStyle
        {
            get
            {
                return new StyleItem(divDesignViewStyleValue[0],
                string.Format(f1, ClassName, divDesignViewStyleValue[1]));
            }
        }

        public StyleItem DropDownClassNameListHoverStyle
        {
            get
            {
                return new StyleItem(dropDownClassNameListHoverStyleValue[0],
                string.Format(f1, ClassName, dropDownClassNameListHoverStyleValue[1]));
            }
        }

        public StyleItem DropDownClassNameListStyle
        {
            get
            {
                return new StyleItem(dropDownClassNameListStyleValue[0],
                string.Format(f1, ClassName, dropDownClassNameListStyleValue[1]));
            }
        }

        public StyleItem DropDownFontnameHoverStyle
        {
            get
            {
                return new StyleItem(dropDownFontnameHoverStyleValue[0],
                string.Format(f1, ClassName, dropDownFontnameHoverStyleValue[1]));
            }
        }

        public StyleItem DropDownFontnameStyle
        {
            get
            {
                return new StyleItem(dropDownFontnameStyleValue[0],
                string.Format(f1, ClassName, dropDownFontnameStyleValue[1]));
            }
        }

        public StyleItem DropDownFontsizeHoverStyle
        {
            get
            {
                return new StyleItem(dropDownFontsizeHoverStyleValue[0],
                string.Format(f1, ClassName, dropDownFontsizeHoverStyleValue[1]));
            }
        }

        public StyleItem DropDownFontsizeStyle
        {
            get
            {
                return new StyleItem(dropDownFontsizeStyleValue[0],
                string.Format(f1, ClassName, dropDownFontsizeStyleValue[1]));
            }
        }

        public StyleItem DropDownFormatblockHoverStyle
        {
            get
            {
                return new StyleItem(dropDownFormatblockHoverStyleValue[0],
                string.Format(f1, ClassName, dropDownFormatblockHoverStyleValue[1]));
            }
        }

        public StyleItem DropDownFormatblockStyle
        {
            get
            {
                return new StyleItem(dropDownFormatblockStyleValue[0],
                string.Format(f1, ClassName, dropDownFormatblockStyleValue[1]));
            }
        }

        public StyleItem DropDownHeaderStyle
        {
            get
            {
                return new StyleItem(dropDownHeaderStyleValue[0],
                string.Format(f1, ClassName, dropDownHeaderStyleValue[1]));
            }
        }

        public StyleItem DropDownSpellCheckerActiveStyle
        {
            get
            {
                return new StyleItem(dropDownSpellCheckerActiveStyleValue[0],
                string.Format(f1, ClassName, dropDownSpellCheckerActiveStyleValue[1]));
            }
        }

        public StyleItem DropDownSpellCheckerHoverStyle
        {
            get
            {
                return new StyleItem(dropDownSpellCheckerHoverStyleValue[0],
                string.Format(f1, ClassName, dropDownSpellCheckerHoverStyleValue[1]));
            }
        }

        public StyleItem DropDownSpellCheckerStyle
        {
            get
            {
                return new StyleItem(dropDownSpellCheckerStyleValue[0],
                string.Format(f1, ClassName, dropDownSpellCheckerStyleValue[1]));
            }
        }

        public StyleItem DropDownSpellSuggestionHoverStyle
        {
            get
            {
                return new StyleItem(dropDownSpellSuggestionHoverStyleValue[0],
                string.Format(f1, ClassName, dropDownSpellSuggestionHoverStyleValue[1]));
            }
        }

        public StyleItem DropDownSpellSuggestionMenuItemHoverStyle
        {
            get
            {
                return new StyleItem(dropDownSpellSuggestionMenuItemHoverStyleValue[0],
                string.Format(f1, ClassName,
                dropDownSpellSuggestionMenuItemHoverStyleValue[1]));
            }
        }

        public StyleItem DropDownSpellSuggestionMenuItemStyle
        {
            get
            {
                return new StyleItem(dropDownSpellSuggestionMenuItemStyleValue[0],
                string.Format(f1, ClassName, dropDownSpellSuggestionMenuItemStyleValue[1]));
            }
        }

        public StyleItem DropDownSpellSuggestionMenuStyle
        {
            get
            {
                return new StyleItem(dropDownSpellSuggestionMenuStyleValue[0],
                string.Format(f1, ClassName, dropDownSpellSuggestionMenuStyleValue[1]));
            }
        }

        public StyleItem DropDownStyle
        {
            get
            {
                return new StyleItem(dropDownStyleValue[0],
                string.Format(f1, ClassName, dropDownStyleValue[1]));
            }
        }

        public StyleItem Editor
        {
            get
            {
                return new StyleItem(editorValue, ClassName);
            }
        }

        public StyleItem FirstButtonStyle
        {
            get
            {
                return new StyleItem(firstButtonStyleValue[0],
                string.Format(f1, ClassName, firstButtonStyleValue[1]));
            }
        }

        public StyleItem FloatingToolBarStyle
        {
            get
            {
                return new StyleItem(floatingToolBarStyleValue[0],
                    string.Format(f1, ClassName, floatingToolBarStyleValue[1]));
            }
        }

        public StyleItem HtmlElementHilightStyle
        {
            get
            {
                return new StyleItem(htmlElementHilightStyleValue[0],
                string.Format(f1, ClassName, htmlElementHilightStyleValue[1]));
            }
        }

        public StyleItem HtmlViewColorHilightStyle
        {
            get
            {
                return new StyleItem(htmlViewColorHilightStyleValue[0],
                string.Format(f1, ClassName, htmlViewColorHilightStyleValue[1]));
            }
        }

        public StyleItem HtmlViewStyle
        {
            get
            {
                return new StyleItem(htmlViewStyleValue[0],
                string.Format(f1, ClassName, htmlViewStyleValue[1]));
            }
        }

        public StyleItem IFrameBodyStyle
        {
            get
            {
                return new StyleItem(iFrameBodyStyleValue[0],
                string.Format(f1, ClassName, iFrameBodyStyleValue[1]));
            }
        }

        public StyleItem IFrameHtmlStyle
        {
            get
            {
                return new StyleItem(iFrameHtmlStyleValue[0],
                string.Format(f1, ClassName, iFrameHtmlStyleValue[1]));
            }
        }

        public StyleItem ImagePicker
        {
            get
            {
                return new StyleItem(imagePickerValue, ClassName);
            }
        }

        public StyleItem LastButtonStyle
        {
            get
            {
                return new StyleItem(lastButtonStyleValue[0],
                string.Format(f1, ClassName, lastButtonStyleValue[1]));
            }
        }

        public StyleItem ListItemDesignViewStyle
        {
            get
            {
                return new StyleItem(listItemDesignViewStyleValue[0],
                string.Format(f1, ClassName, listItemDesignViewStyleValue[1]));
            }
        }

        public StyleItem MediaFrame
        {
            get
            {
                return new StyleItem(mediaFrameValue, ClassName);
            }
        }

        public StyleItem MediaFrameBodyStyle
        {
            get
            {
                return new StyleItem(mediaFrameBodyStyleValue[0],
                string.Format(f1, ClassName, mediaFrameBodyStyleValue[1]));
            }
        }

        public StyleItem MediaFrameCloseButtonStyle
        {
            get
            {
                return new StyleItem(mediaFrameCloseButtonStyleValue[0],
                string.Format(f1, ClassName, mediaFrameCloseButtonStyleValue[1]));
            }
        }

        public StyleItem MediaFrameHeaderCaptionStyle
        {
            get
            {
                return new StyleItem(mediaFrameHeaderCaptionStyleValue[0],
                string.Format(f1, ClassName, mediaFrameHeaderCaptionStyleValue[1]));
            }
        }

        public StyleItem MediaFrameHeaderStyle
        {
            get
            {
                return new StyleItem(mediaFrameHeaderStyleValue[0],
                string.Format(f1, ClassName, mediaFrameHeaderStyleValue[1]));
            }
        }

        public StyleItem MediaFrameStyle
        {
            get
            {
                return new StyleItem(mediaFrameStyleValue[0],
                string.Format(f1, ClassName, mediaFrameStyleValue[1]));
            }
        }

        public StyleItem NextButtonStyle
        {
            get
            {
                return new StyleItem(nextButtonStyleValue[0],
                string.Format(f1, ClassName, nextButtonStyleValue[1]));
            }
        }

        public StyleItem PagerButtonHoverStyle
        {
            get
            {
                return new StyleItem(pagerButtonHoverStyleValue[0],
                string.Format(f1, ClassName, pagerButtonHoverStyleValue[1]));
            }
        }

        public StyleItem PagerButtonStyle
        {
            get
            {
                return new StyleItem(pagerButtonStyleValue[0],
                string.Format(f1, ClassName, pagerButtonStyleValue[1]));
            }
        }

        public StyleItem ParagraphDesignViewStyle
        {
            get
            {
                return new StyleItem(paragraphDesignViewStyleValue[0],
                string.Format(f1, ClassName, paragraphDesignViewStyleValue[1]));
            }
        }

        public StyleItem PauseButtonStyle
        {
            get
            {
                return new StyleItem(pauseButtonStyleValue[0],
                string.Format(f1, ClassName, pauseButtonStyleValue[1]));
            }
        }

        public StyleItem PopupBodyStyle
        {
            get
            {
                return new StyleItem(popupBodyStyleValue[0],
                string.Format(f1, ClassName, popupBodyStyleValue[1]));
            }
        }

        public StyleItem PopupHeaderCaptionStyle
        {
            get
            {
                return new StyleItem(popupHeaderCaptionStyleValue[0],
                string.Format(f1, ClassName, popupHeaderCaptionStyleValue[1]));
            }
        }

        public StyleItem PopupHeaderStyle
        {
            get
            {
                return new StyleItem(popupHeaderStyleValue[0],
                string.Format(f1, ClassName, popupHeaderStyleValue[1]));
            }
        }

        public StyleItem PopupStyle
        {
            get
            {
                return new StyleItem(popupStyleValue[0],
                string.Format(f1, ClassName, popupStyleValue[1]));
            }
        }

        public StyleItem PreviousButtonStyle
        {
            get
            {
                return new StyleItem(previousButtonStyleValue[0],
                string.Format(f1, ClassName, previousButtonStyleValue[1]));
            }
        }

        public StyleItem ProgressbarMessageStyle
        {
            get
            {
                return new StyleItem(progressbarMessageStyleValue[0],
                string.Format(f1, ClassName, progressbarMessageStyleValue[1]));
            }
        }

        public StyleItem ProgressbarStyle
        {
            get
            {
                return new StyleItem(progressbarStyleValue[0],
                string.Format(f1, ClassName, progressbarStyleValue[1]));
            }
        }

        public StyleItem SelectedPagerButtonStyle
        {
            get
            {
                return new StyleItem(selectedPagerButtonStyleValue[0],
                string.Format(f1, ClassName, selectedPagerButtonStyleValue[1]));
            }
        }

        public StyleItem SlideShowButtonStyle
        {
            get
            {
                return new StyleItem(slideShowButtonStyleValue[0],
                string.Format(f1, ClassName, slideShowButtonStyleValue[1]));
            }
        }

        public StyleItem SpanDesignViewStyle
        {
            get
            {
                return new StyleItem(spanDesignViewStyleValue[0],
                string.Format(f1, ClassName, spanDesignViewStyleValue[1]));
            }
        }

        public StyleItem TabContainerStyle
        {
            get
            {
                return new StyleItem(tabContainerStyleValue[0],
                    string.Format(f1, ClassName, tabContainerStyleValue[1]));
            }
        }

        public StyleItem TabItemHoverStyle
        {
            get
            {
                return new StyleItem(tabItemHoverStyleValue[0],
                    string.Format(f1, ClassName, tabItemHoverStyleValue[1]));
            }
        }

        public StyleItem TableCellDesignViewStyle
        {
            get
            {
                return new StyleItem(tableCellDesignViewStyleValue[0],
                string.Format(f1, ClassName, tableCellDesignViewStyleValue[1]));
            }
        }

        public StyleItem ThumbnailsContainerStyle
        {
            get
            {
                return new StyleItem(thumbnailsContainerStyleValue[0],
                string.Format(f1, ClassName, thumbnailsContainerStyleValue[1]));
            }
        }

        public StyleItem ThumbnailStyle
        {
            get
            {
                return new StyleItem(thumbnailStyleValue[0],
                string.Format(f1, ClassName, thumbnailStyleValue[1]));
            }
        }

        public StyleItem ToolBarItemHoverStyle
        {
            get
            {
                return new StyleItem(toolBarItemHoverStyleValue[0],
                    string.Format(f1, ClassName, toolBarItemHoverStyleValue[1]));
            }
        }

        public StyleItem UpdatePanelProgress
        {
            get
            {
                return new StyleItem(updatePanelProgressValue, ClassName);
            }
        }

        public StyleItem WarningsLogStyle
        {
            get
            {
                return new StyleItem(warningsLogStyleValue[0],
                string.Format(f1, ClassName, warningsLogStyleValue[1]));
            }
        }

        string ClassName
        {
            get
            {
                return classNameValue;
            }
        }

        #endregion Properties

        #region Methods

        public static string GetColorPickerStyles(HttpContext context, NameValueCollection nvc)
        {
            ColorPicker colorPicker1 = new ColorPicker();
            Page p = new Page();
            HtmlForm hf = new HtmlForm();
            p.Controls.Add(hf);
            hf.Controls.Add(colorPicker1);
            p.DesignerInitialize();

            SkinNames colorPickerSkin = (SkinNames)Enum.Parse(typeof(SkinNames),
                (string)(nvc["s"] ?? SkinNames.Classic.ToString()));
            colorPicker1.Skin = colorPickerSkin;

            string customSkin = (string)(nvc["cs"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkin) && !customSkin.Equals("None"))
                colorPicker1.CustomSkin = customSkin;

            string customSkinFolder = (string)(nvc["csf"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkinFolder))
                colorPicker1.CustomSkinFolder = customSkinFolder;

            string cssClass = nvc["cc"];
            if (!string.IsNullOrEmpty(cssClass))
                colorPicker1.CssClass = cssClass;

            bool formatCss = false;
            if (bool.TryParse(nvc["fcss"], out formatCss))
                colorPicker1.FormatCss = formatCss;

            CssFile fileToRetrieve = (CssFile)Enum.Parse(typeof(CssFile),
                                    (string)(nvc["cssfile"] ?? CssFile.Auto.ToString()));
            string css = string.Empty;
            switch (fileToRetrieve)
            {
                case CssFile.Auto:
                    css = colorPicker1.GetCssStyle();
                    break;
                case CssFile.Shared:
                    css = colorPicker1.GetSharedCssStyle();
                    break;
            }
            p.Dispose();
            p = null;
            return formatCss ? css :  Helper.TrimWhiteSpace(css);
        }

        public static string GetEditorStyles(HttpContext context, NameValueCollection nvc)
        {
            Editor editor1 = new Editor();
            Page p = new Page();
            HtmlForm hf = new HtmlForm();
            p.Controls.Add(hf);
            hf.Controls.Add(editor1);
            p.DesignerInitialize();

            SkinNames editorSkin = (SkinNames)Enum.Parse(typeof(SkinNames),
                (string)(nvc["s"] ?? SkinNames.Classic.ToString()));
            editor1.Skin = editorSkin;

            string customSkin = (string)(nvc["cs"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkin) && !customSkin.Equals("None"))
                editor1.CustomSkin = customSkin;

            string customSkinFolder = (string)(nvc["csf"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkinFolder))
                editor1.CustomSkinFolder = customSkinFolder;

            IconType iconsMode = (IconType)Enum.Parse(typeof(IconType),
                (string)(nvc["im"] ?? IconType.ImageSprites.ToString()));
            editor1.IconsMode = iconsMode;

            Dir direction = (Dir)Enum.Parse(typeof(Dir),
                (string)(nvc["dir"] ?? Dir.LTR.ToString()));
            editor1.Direction = direction;

            string cssClass = nvc["cc"];
            if (!string.IsNullOrEmpty(cssClass))
                editor1.CssClass = cssClass;

            ToolBarType toolBarMode = (ToolBarType)Enum.Parse(typeof(ToolBarType),
                (string)(nvc["tbm"] ?? ToolBarType.Advanced.ToString()));
            editor1.ToolBarMode = toolBarMode;

            bool formatCss = false;
            if (bool.TryParse(nvc["fcss"], out formatCss))
                editor1.FormatCss = formatCss;

            CssFile fileToRetrieve = (CssFile)Enum.Parse(typeof(CssFile),
                                    (string)(nvc["cssfile"] ?? CssFile.Auto.ToString()));
            string css = string.Empty;
            switch (fileToRetrieve)
            {
                case CssFile.Auto:
                    css = editor1.GetCssStyle();
                    break;
                case CssFile.Shared:
                    css = editor1.GetSharedCssStyle();
                    break;
                case CssFile.TreeView:
                    css = editor1.GetTreeViewCssStyle();
                    break;
            }
            p.Dispose();
            p = null;
            return formatCss ? css :  Helper.TrimWhiteSpace(css);
        }

        public static string GetImagePickerStyles(HttpContext context, NameValueCollection nvc)
        {
            ImagePicker imagePicker1 = new ImagePicker();
            Page p = new Page();
            HtmlForm hf = new HtmlForm();
            p.Controls.Add(hf);
            hf.Controls.Add(imagePicker1);
            p.DesignerInitialize();

            SkinNames imagePickerSkin = (SkinNames)Enum.Parse(typeof(SkinNames),
                (string)(nvc["s"] ?? SkinNames.Classic.ToString()));
            imagePicker1.Skin = imagePickerSkin;

            string customSkin = (string)(nvc["cs"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkin) && !customSkin.Equals("None"))
                imagePicker1.CustomSkin = customSkin;

            string customSkinFolder = (string)(nvc["csf"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkinFolder))
                imagePicker1.CustomSkinFolder = customSkinFolder;

            string cssClass = nvc["cc"];
            if (!string.IsNullOrEmpty(cssClass))
                imagePicker1.CssClass = cssClass;

            bool formatCss = false;
            if (bool.TryParse(nvc["fcss"], out formatCss))
                imagePicker1.FormatCss = formatCss;

            CssFile fileToRetrieve = (CssFile)Enum.Parse(typeof(CssFile),
                                    (string)(nvc["cssfile"] ?? CssFile.Auto.ToString()));
            string css = string.Empty;
            switch (fileToRetrieve)
            {
                case CssFile.Auto:
                    css = imagePicker1.GetCssStyle();
                    break;
                case CssFile.Shared:
                    css = imagePicker1.GetSharedCssStyle();
                    break;
                case CssFile.TreeView:
                    css = imagePicker1.GetTreeViewCssStyle();
                    break;
            }
            p.Dispose();
            p = null;
            return formatCss ? css :  Helper.TrimWhiteSpace(css);
        }

        public static string GetMediaFrameStyles(HttpContext context, NameValueCollection nvc)
        {
            MediaFrame mediaFrame1 = new MediaFrame();
            Page p = new Page();
            HtmlForm hf = new HtmlForm();
            p.Controls.Add(hf);
            hf.Controls.Add(mediaFrame1);
            p.DesignerInitialize();

            SkinNames mediaFrameSkin = (SkinNames)Enum.Parse(typeof(SkinNames),
                (string)(nvc["s"] ?? SkinNames.Classic.ToString()));
            mediaFrame1.Skin = mediaFrameSkin;

            string customSkin = (string)(nvc["cs"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkin) && !customSkin.Equals("None"))
                mediaFrame1.CustomSkin = customSkin;

            string customSkinFolder = (string)(nvc["csf"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkinFolder))
                mediaFrame1.CustomSkinFolder = customSkinFolder;

            string cssClass = nvc["cc"];
            if (!string.IsNullOrEmpty(cssClass))
                mediaFrame1.CssClass = cssClass;

            bool formatCss = false;
            if (bool.TryParse(nvc["fcss"], out formatCss))
                mediaFrame1.FormatCss = formatCss;

            CssFile fileToRetrieve = (CssFile)Enum.Parse(typeof(CssFile),
                                    (string)(nvc["cssfile"] ?? CssFile.Auto.ToString()));
            string css = string.Empty;
            switch (fileToRetrieve)
            {
                case CssFile.Auto:
                    css = mediaFrame1.GetCssStyle();
                    break;
                case CssFile.Shared:
                    css = mediaFrame1.GetSharedCssStyle();
                    break;
            }
            p.Dispose();
            p = null;
            return formatCss ? css :  Helper.TrimWhiteSpace(css);
        }

        public static string GetSlidePaneStyles(HttpContext context, NameValueCollection nvc)
        {
            SlidePane slidePane1 = new SlidePane();
            Page p = new Page();
            HtmlForm hf = new HtmlForm();
            p.Controls.Add(hf);
            hf.Controls.Add(slidePane1);
            p.DesignerInitialize();

            SkinNames SlidePaneSkin = (SkinNames)Enum.Parse(typeof(SkinNames),
                (string)(nvc["s"] ?? SkinNames.Classic.ToString()));
            slidePane1.Skin = SlidePaneSkin;

            string customSkin = (string)(nvc["cs"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkin) && !customSkin.Equals("None"))
                slidePane1.CustomSkin = customSkin;

            string customSkinFolder = (string)(nvc["csf"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkinFolder))
                slidePane1.CustomSkinFolder = customSkinFolder;

            string cssClass = nvc["cc"];
            if (!string.IsNullOrEmpty(cssClass))
                slidePane1.CssClass = cssClass;

            bool formatCss = false;
            if (bool.TryParse(nvc["fcss"], out formatCss))
                slidePane1.FormatCss = formatCss;

            CssFile fileToRetrieve = (CssFile)Enum.Parse(typeof(CssFile),
                                    (string)(nvc["cssfile"] ?? CssFile.Auto.ToString()));
            string css = string.Empty;
            switch (fileToRetrieve)
            {
                case CssFile.Auto:
                    css = slidePane1.GetCssStyle();
                    break;
            }
            p.Dispose();
            p = null;
            return formatCss ? css :  Helper.TrimWhiteSpace(css);
        }

        public static string GetUpdatePanelProgressStyles(HttpContext context, NameValueCollection nvc)
        {
            UpdatePanelProgress updatePanelProgress1 = new UpdatePanelProgress();
            Page p = new Page();
            HtmlForm hf = new HtmlForm();
            p.Controls.Add(hf);
            hf.Controls.Add(updatePanelProgress1);
            p.DesignerInitialize();

            SkinNames updatePanelProgressSkin = (SkinNames)Enum.Parse(typeof(SkinNames),
                (string)(nvc["s"] ?? SkinNames.Classic.ToString()));
            updatePanelProgress1.Skin = updatePanelProgressSkin;

            string customSkin = (string)(nvc["cs"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkin) && !customSkin.Equals("None"))
                updatePanelProgress1.CustomSkin = customSkin;

            string customSkinFolder = (string)(nvc["csf"] ?? string.Empty);
            if (!string.IsNullOrEmpty(customSkinFolder))
                updatePanelProgress1.CustomSkinFolder = customSkinFolder;

            string cssClass = nvc["cc"];
            if (!string.IsNullOrEmpty(cssClass))
                updatePanelProgress1.CssClass = cssClass;

            bool formatCss = false;
            if (bool.TryParse(nvc["fcss"], out formatCss))
                updatePanelProgress1.FormatCss = formatCss;

            CssFile fileToRetrieve = (CssFile)Enum.Parse(typeof(CssFile),
                                    (string)(nvc["cssfile"] ?? CssFile.Auto.ToString()));
            string css = string.Empty;
            switch (fileToRetrieve)
            {
                case CssFile.Auto:
                    css = updatePanelProgress1.GetCssStyle();
                    break;
                case CssFile.Shared:
                    css = updatePanelProgress1.GetSharedCssStyle();
                    break;
            }
            p.Dispose();
            p = null;
            return formatCss ? css :  Helper.TrimWhiteSpace(css);
        }

        public StyleItem TabItemStyle(string className)
        {
            return new StyleItem(tabItemStyleValue,
                    string.Format(f2, className, "b"));
        }

        public StyleItem TabStyle(string className)
        {
            return new StyleItem(tabStyleValue, className);
        }

        public StyleItem ToolBarItemStyle(string className)
        {
            return new StyleItem(toolBarItemStyleValue,
                string.Format(f2, className, "b"));
        }

        public StyleItem ToolBarStyle(string className)
        {
            return new StyleItem(toolBarStyleValue, className);
        }

        #endregion Methods
    }
}